package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MedicineSettingDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.MedicineSetting;
import com.itheima.service.MedicineSettingService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZhaoShengChao
 * @create 2021/8/7 21:45
 */
@Service(interfaceClass=MedicineSettingService.class)
@Transactional
public class MedicineSettingServiceImpl implements MedicineSettingService {


    @Autowired
    private MedicineSettingDao medicineSettingDao;

    /**
     * 文件上传
     * @param medicineSettings
     */
    @Override
    public void add(List<MedicineSetting> medicineSettings) {
        if (medicineSettings != null&&medicineSettings.size() > 0) {

            for (MedicineSetting medicineSetting : medicineSettings) {
                medicineSettingDao.add(medicineSetting);
            }
        }
    }

    @Override
    public void add(MedicineSetting medicineSetting) {
            medicineSettingDao.add(medicineSetting);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //当前页
        Integer currentPage = queryPageBean.getCurrentPage();
        //每页显示几条数据
        Integer pageSize = queryPageBean.getPageSize();
        //查询条件
        String queryString = queryPageBean.getQueryString();

        //分页助手插件
        PageHelper.startPage(currentPage,pageSize);

        Page<MedicineSetting> list = medicineSettingDao.findByCondition(queryString);

        //总条数
        long total = list.getTotal();
        //全部数据
        List<MedicineSetting> result = list.getResult();

        return new PageResult(total,result);
    }

    /**
     * 删除数据
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        medicineSettingDao.deleteById(id);
    }

    /**
     * 编辑运动数据
     * @param medicineSetting
     */
    @Override
    public void edit(MedicineSetting medicineSetting) {
        medicineSettingDao.edit(medicineSetting);
    }
}
